package com.wonghiu.framework.cluster.loadbalance;

import com.wonghiu.framework.exchange.HRpcRequest;

import java.util.List;

/**
 * @Author wonghiu
 * @Date 2021/8/10 20:21
 * @Version 1.0.1
 */
public abstract class AbstractLoadBalance implements LoadBalance {
    @Override
    public String selectServiceAddress(List<String> serviceAddresses, HRpcRequest rpcRequest) {
        if (serviceAddresses == null || serviceAddresses.size() == 0) {
            return null;
        }
        if (serviceAddresses.size() == 1) {
            return serviceAddresses.get(0);
        }
        return doSelect(serviceAddresses, rpcRequest);
    }

    protected abstract String doSelect(List<String> serviceAddresses, HRpcRequest rpcRequest);

}
